package cn.kgc.controller;

import cn.kgc.dto.Dto;
import cn.kgc.dto.DtoUtil;
import cn.kgc.service.ItemService;
import cn.kgc.vo.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api")

public class ItemController {

    @Autowired
    ItemService itemService;

    /**
     * 根据商品id返回商品详情页
     * @param id
     * @return
     * @throws Exception
     */
    @PostMapping("/p/queryItemDetail/{id}")
    public Dto<QueryItemDetailVo> getDmImageById(@PathVariable Integer id ) throws Exception {

            return  itemService.queryItemDetail(id);
    }

    /**
     * 根据商品ID查询商品排期
     * @param itemId
     * @return
     * @throws Exception
     */
    @PostMapping("/p/queryItemScheduler/{itemId}")
    public Dto<ItemSchedulerVo> queryItemScheduler(@PathVariable  Integer itemId) throws Exception {
        return itemService.queryItemScheduler(itemId);
    }

    /**
     * 根据商品排期查询商品价格
     * @param schedulerId
     * @return
     * @throws Exception
     */
    @PostMapping("/p/queryItemPrice/{schedulerId}")
    public Dto<List<ItemPriceVo>> queryItemPrice(@PathVariable  Integer schedulerId) throws Exception {
        Dto<List<ItemPriceVo>> itemPriceList = itemService.queryItemPrice(schedulerId);
        return DtoUtil.returnDataSuccess(itemPriceList);
    }

    /**
     * 根据商品Id获取该商品剧评
     * @param id
     * @return
     * @throws Exception
     */
    @PostMapping("/p/queryItemComment/{id}")
    public Dto<List<ItemPriceByCommentVo>> queryItemComment(@PathVariable  Integer id) throws Exception {
        return itemService.queryItemComment(id);
    }

    //添加剧评
    @RequestMapping("v/commitItemComment")
    public Dto<DtoUtil> commitItemComment(@RequestBody ItemAddCommetVo itemAddCommetVo) throws Exception {
        return itemService.commitItemComment(itemAddCommetVo);
    }

    //推荐接口
    @PostMapping("p/queryItemRecommend")
    public Dto<List<ItemRecommendVo>> queryItemRecommend(@RequestParam Integer itemTypeId, @RequestParam Integer limit) throws Exception {
        List<List<ItemRecommendVo>> itemReList = itemService.queryItemRecommend(itemTypeId, limit);

        return  DtoUtil.returnDataSuccess(itemReList);

    }
}
